﻿Public Class frm_CRC

    Private Sub btn_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Close.Click
        frm_Win_Navi.Del_Win(Me.Text)
        If frm_Main.ActiveMdiChild.Name <> Me.Name Then Me.Select()
        Me.Close()
    End Sub

    Private Sub frm_CRC_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Label_Refresh(Me.Text)
        Selected_ID = Me.Name
        '  Call Form_Setup()
    End Sub


    Private Sub frm_CRC_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call Form_Setup()
    End Sub

    Private Sub Form_Setup()
        If Simulation_Mode = True Then
            lbl_DC.Text = "Simulaton Mode"
        Else
            lbl_DC.Text = "0"
        End If
        lbl_FC.Text = "0"
        lbl_Comp.Text = "Match / Error"
        lbl_FileName.Text = "No File Loaded"
        lv_Reg.Items.Clear()
    End Sub

    Private Sub btn_Read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Read.Click
        If Simulation_Mode = True Then
            lbl_DC.Text = "Simulaton Mode"
        Else
            lbl_DC.Text = Hex(Device_CRC(Me.Name))
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dir As String
        dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
        LoadBoard.InitialDirectory = dir + "\Analog Devices Inc\ADP101055"
        'LoadBoard.InitialDirectory = Application.StartupPath + "\Register Settings"
        LoadBoard.FileName = ""
        LoadBoard.Filter = "Register Setup File |*.55s"
        LoadBoard.ShowDialog()
        lbl_FileName.Text = LoadBoard.SafeFileName
        If LoadBoard.FileName <> "" Then
            lbl_FC.Text = Hex(File_CRC(LoadBoard.FileName, Selected_ID))
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim objListItem As ListViewItem
        Dim str(3) As String
        Dim temp As String
        Dim temp_num As Integer
        Dim count As Integer = 0
        temp = "Match"

        lv_Reg.Items.Clear()
        For i = 0 To Max_Reg_Val
            If (Reg(i, 1) = "RW" Or Reg(i, 1) = "WO") And Reg(i, 3) = 0 And i <> &H1B And i <> &HF4 And i <> &HF5 Then
                If Reg_Value(i, Me.Name) <> Reg_Value_CRC(i, Me.Name) Then
                    If i < 255 Then
                        objListItem = lv_Reg.Items.Add(Hex(i) + " h")
                    Else
                        temp_num = i - 256
                        If temp_num < 16 Then
                            objListItem = lv_Reg.Items.Add("FE0" + Hex(temp_num) + " h")
                        Else
                            objListItem = lv_Reg.Items.Add("FE" + Hex(temp_num) + " h")
                        End If

                    End If

                    objListItem.SubItems.Add(Reg(i, 0))
                    objListItem.SubItems.Add(Hex(Reg_Value(i, Me.Name)) + " h")
                    objListItem.SubItems.Add(Hex(Reg_Value_CRC(i, Me.Name)) + " h")
                    temp = "Error"
                End If

            ElseIf i = &H1B Or i = &HF4 Or i = &HF5 Then
                If checksum_block(count, 0) <> checksum_block(count, 1) Then
                    objListItem = lv_Reg.Items.Add(Hex(i) + " h")
                    objListItem.SubItems.Add(Reg(i, 0))
                    objListItem.SubItems.Add(checksum_block(count, 1) + " h")
                    objListItem.SubItems.Add(checksum_block(count, 0) + " h")
                    temp = "Error"

                End If
                count = count + 1
            End If




        Next

        lbl_Comp.Text = temp
    End Sub
End Class